


#include "user_inc.h"






void Windowfilter_init(Windowfilter_t* hd,uint16_t ww,Windowfilter_cb cb,size_t init_val)
{
    if (hd == 0)
    {
        return ;
    }

    if (ww == 0)
    {
        return ;
    }    

    hd->lv = init_val * ww;
    hd->ww =ww;
    hd->cb = cb;   

}

void Windowfilter_add_val(Windowfilter_t* hd,size_t val)
{
    if (hd == 0)
    {
        return ;
    }

    if (hd->ww == 0)
    {
        return ;
    }


    if (hd->cb == 0)
    {
        hd->lv = hd->lv + val -hd->lv/hd->ww;
    }
    else
    {

        size_t a1;
        a1 =hd->cb(hd->lv,val,0);

        hd->lv = hd->cb(a1,hd->lv/hd->ww,1);


    }
    
    



}

size_t Windowfilter_get_data(Windowfilter_t* hd)
{
    if (hd == 0)
    {
        return 0;
    }

    if (hd->ww == 0)
    {
        return 0;
    }

    return hd->lv / hd->ww;

}















